Skip to main content
Ctrl+K
Currently the document is still under construction.
Dara Documentation - Home
  • GitHub
  • Overview
  • Installation
  • Tutorials
    • 1. Automated Refinement with BGMN
    • 2. Phase Searching with Tree Search
  • API Docs
    • dara package
      • dara.bgmn package
        • dara.bgmn.download_bgmn module
      • dara.data package
      • dara.prediction package
        • dara.prediction.base module
        • dara.prediction.core module
        • dara.prediction.rn module
        • dara.prediction.rxn_ca module
      • dara.search package
        • dara.search.core module
        • dara.search.data_model module
        • dara.search.peak_matcher module
        • dara.search.tree module
      • dara.bgmn_worker module
      • dara.cif module
      • dara.cif2str module
      • dara.eflech_worker module
      • dara.generate_control_file module
      • dara.jobs module
      • dara.peak_detection module
      • dara.plot module
      • dara.refine module
      • dara.result module
      • dara.schema module
      • dara.settings module
      • dara.structure_db module
      • dara.utils module
      • dara.xrd module
  • Repository
  • Show source
  • .ipynb

Tutorial 2: Phase search

Contents

  • Step 1: Prepare reference phases
  • Step 2: Search for phases
  • Step 3: Result analysis

Tutorial 2: Phase search#

Dara is equipped with a tree-search-based algorithm to predict the phases present in a given pattern.

In this tutorial, we will try to understand the phases in one sample from pairwise reaction between GeO2 and ZnO.

from dara import search_phases
from pathlib import Path
pattern_path = "tutorial_data/GeO2-ZnO_700C_60min.xrdml"

# three elements are present in the sample
chemical_system = "Zn-Ge-O" 

Step 1: Prepare reference phases#

Dara pre-builds an index of all the unique and low-energy phases in ICSD and COD databases. It also implements a method to download CIF structures from COD data server so that there is no need to obtain the offline database.

Before every search, we will need to gather all the reference phases in the chemical system for the search algorithm. Dara provides ICSDDatabase and CODDatabase to do the filtering.

In this example, we will use CODDatabase to download all the phases in the chemical system of Ge-Zn-O.

from dara.structure_db import CODDatabase

# The COD database contains methods to filter phases in the chemical system
cod_database = CODDatabase()

# gather reference phases and save them to a directory called "cifs"
all_cod_ids = cod_database.get_cifs_by_chemsys(chemical_system, dest_dir="cifs")
2024-06-26 17:36:35,439 WARNING dara.structure_db Local copy of database not found. Attempting to download structures...
2024-06-26 17:36:36,602 INFO dara.structure_db Saving downloaded CIFs to dara_downloaded_cifs
Skipping high-energy phase: 1528389 (Ge, 96): e_hull = 0.1494
Skipping high-energy phase: 9013109 (Ge, 64): e_hull = 0.3137
2024-06-26 17:36:36,613 INFO dara.structure_db Skipping common gas: O2
2024-06-26 17:36:36,614 INFO dara.structure_db Skipping common gas: O2
2024-06-26 17:36:36,615 INFO dara.structure_db Skipping common gas: O2
2024-06-26 17:36:36,616 INFO dara.structure_db Skipping common gas: O2
2024-06-26 17:36:36,617 INFO dara.structure_db Skipping common gas: O2
2024-06-26 17:36:36,618 INFO dara.structure_db Skipping common gas: O2
2024-06-26 17:36:36,618 INFO dara.structure_db Skipping common gas: O2
2024-06-26 17:36:36,619 INFO dara.structure_db Skipping common gas: O2
2024-06-26 17:36:36,620 INFO dara.structure_db Skipping common gas: O2
2024-06-26 17:36:36,621 INFO dara.structure_db Skipping common gas: O2
2024-06-26 17:36:36,622 INFO dara.structure_db Skipping common gas: O2
2024-06-26 17:36:36,622 INFO dara.structure_db Skipping common gas: O2
2024-06-26 17:36:36,623 INFO dara.structure_db Skipping common gas: O2
Skipping high-energy phase: 1525835 (GeO2, 205): e_hull = 0.2246
Skipping high-energy phase: 1533322 (Ge7O23, 215): e_hull = 0.6571
Skipping high-energy phase: 1011223 (ZnO2, 19): e_hull = 0.1674
Skipping high-energy phase: 1529590 (ZnO2, 164): e_hull = 0.4588
Skipping high-energy phase: 1534836 (ZnO, 225): e_hull = 0.1473
Successfully copied 9011050.cif to Ge_227_(cod_9011050)-0.cif in cifs
Successfully copied 7101738.cif to Ge_227_(cod_7101738)-0.cif in cifs
Successfully copied 9012435.cif to Zn_194_(cod_9012435)-0.cif in cifs
Successfully copied 4030923.cif to Zn_12_(cod_4030923)-None.cif in cifs
Successfully copied 1538108.cif to O17.28_12_(cod_1538108)-None.cif in cifs
Successfully copied 9007435.cif to GeO2_136_(cod_9007435)-0.cif in cifs
Successfully copied 1525833.cif to GeO2_60_(cod_1525833)-36.cif in cifs
Successfully copied 2104024.cif to GeO2_60_(cod_2104024)-36.cif in cifs
Successfully copied 1526227.cif to GeO2_14_(cod_1526227)-None.cif in cifs
Successfully copied 2300365.cif to GeO2_152_(cod_2300365)-0.cif in cifs
Successfully copied 8000212.cif to Ge5O11_12_(cod_8000212)-None.cif in cifs
Successfully copied 9006858.cif to GeO2_58_(cod_9006858)-6.cif in cifs
Successfully copied 9007477.cif to GeO2_154_(cod_9007477)-0.cif in cifs
Successfully copied 9015579.cif to GeO2_92_(cod_9015579)-1.cif in cifs
Successfully copied 9004178.cif to ZnO_186_(cod_9004178)-0.cif in cifs
Successfully copied 1527883.cif to ZnO2_44_(cod_1527883)-None.cif in cifs
Successfully copied 1536063.cif to Zn10.26O48_160_(cod_1536063)-None.cif in cifs
Successfully copied 1537875.cif to ZnO_216_(cod_1537875)-7.cif in cifs
Successfully copied 4517837.cif to Zn5O12_15_(cod_4517837)-None.cif in cifs
Successfully copied 1007256.cif to Zn2Ge3O8_212_(cod_1007256)-2.cif in cifs
Successfully copied 1549040.cif to Zn2GeO4_227_(cod_1549040)-None.cif in cifs
Successfully copied 1549041.cif to Zn2GeO4_95_(cod_1549041)-None.cif in cifs
Successfully copied 9014631.cif to Zn2GeO4_148_(cod_9014631)-0.cif in cifs

Step 2: Search for phases#

After preparing the reference phases, we can start the phase search. The algorithm will need the reference phases and the pattern to search for the phases.

# gather all the phases in the "cifs" directory
all_cifs = list(Path("cifs").glob("*.cif"))

search_results = search_phases(
    pattern_path=pattern_path,
    phases=all_cifs,
    wavelength="Cu",
    instrument_name="Aeris-fds-Pixcel1d-Medipix3",
)
2024-06-26 17:36:36,704 INFO dara.search.tree Detecting peaks in the pattern.
2024-06-26 17:37:14,175 INFO dara.search.tree The wmax is automatically adjusted to 57.88.
2024-06-26 17:37:14,176 INFO dara.search.tree The intensity threshold is automatically set to 10.00 % of maximum peak intensity.
2024-06-26 17:37:14,177 INFO dara.search.tree Creating the root node.
2024-06-26 17:37:14,180 INFO dara.search.tree Refining all the phases in the dataset.
2024-06-26 17:37:17,242	INFO worker.py:1724 -- Started a local Ray instance.
2024-06-26 17:37:55,168 INFO dara.search.tree Finished refining 16 phases, with 7 phases removed.
(_remote_expand_node pid=2098) 2024-06-26 17:37:55,204 INFO dara.search.tree Expanding node b9a1c334-33e2-11ef-85a9-f1d367ac75b3 with current phases [], Rwp = None
(_remote_expand_node pid=2098) 2024-06-26 17:37:59,627 INFO dara.search.tree Expanding node d490b511-33e2-11ef-85a9-f1d367ac75b3 with current phases [RefinementPhase(path=PosixPath('cifs/GeO2_152_(cod_2300365)-0.cif'), params={})], Rwp = 42.15
(_remote_expand_node pid=2409) 2024-06-26 17:38:07,906 INFO dara.search.tree Expanding node d490b514-33e2-11ef-85a9-f1d367ac75b3 with current phases [RefinementPhase(path=PosixPath('cifs/GeO2_152_(cod_2300365)-0.cif'), params={}), RefinementPhase(path=PosixPath('cifs/ZnO_186_(cod_9004178)-0.cif'), params={})], Rwp = 22.51
(_remote_expand_node pid=2098) 2024-06-26 17:38:01,055 INFO dara.search.tree Expanding node d490b513-33e2-11ef-85a9-f1d367ac75b3 with current phases [RefinementPhase(path=PosixPath('cifs/Zn2GeO4_148_(cod_9014631)-0.cif'), params={})], Rwp = 56.68 [repeated 2x across cluster] (Ray deduplicates logs by default. Set RAY_DEDUP_LOGS=0 to disable log deduplication, or see https://docs.ray.io/en/master/ray-observability/ray-logging.html#log-deduplication for more options.)
(_remote_expand_node pid=2469) 2024-06-26 17:38:13,438 INFO dara.search.tree Expanding node db7b33a0-33e2-11ef-85a9-f1d367ac75b3 with current phases [RefinementPhase(path=PosixPath('cifs/GeO2_152_(cod_2300365)-0.cif'), params={}), RefinementPhase(path=PosixPath('cifs/ZnO_186_(cod_9004178)-0.cif'), params={}), RefinementPhase(path=PosixPath('cifs/Zn2GeO4_148_(cod_9014631)-0.cif'), params={})], Rwp = 12.04
(_remote_expand_node pid=2099) 2024-06-26 17:38:10,272 INFO dara.search.tree Expanding node dad06bf2-33e2-11ef-85a9-f1d367ac75b3 with current phases [RefinementPhase(path=PosixPath('cifs/ZnO_186_(cod_9004178)-0.cif'), params={}), RefinementPhase(path=PosixPath('cifs/Zn2GeO4_148_(cod_9014631)-0.cif'), params={})], Rwp = 44.26

Step 3: Result analysis#

The returned search result will be a list of SearchResult object.

search_results
[SearchResult(refinement_result=RefinementResult(lst_data=LstResult(raw_lst='Rietveld refinement to file(s) GeO2-ZnO_700C_60min.xy\nBGMN version 4.2.23, 4416 measured points, 121 peaks, 24 parameters\nStart: Wed Jun 26 17:38:08 2024; End: Wed Jun 26 17:38:10 2024\n20 iteration steps\n\nRp=9.96%  Rpb=19.06%  R=10.99%  Rwp=12.04% Rexp=2.69%\nDurbin-Watson d=0.10\n1-rho=1.99%\n\nGlobal parameters and GOALs\n****************************\nQGeO2152cod23003650=0.4771+-0.0021\nQZnO186cod90041780=0.3870+-0.0024\nQZn2GeO4148cod90146310=0.1359+-0.0013\nEPS2=-0.002856+-0.000013\n\nLocal parameters and GOALs for phase GeO2152cod23003650\n******************************************************\nSpacegroupNo=152\nHermannMauguin=P3_121\nXrayDensity=4.276\nRphase=10.88%\nUNIT=NM\nA=0.499111+-0.000024\nC=0.564768+-0.000033\nk1=0.0100000\nB1=0.00500000\nGEWICHT=0.2793+-0.0012\nGrainSize(1,1,1)=84.1811\nAtomic positions for phase GeO2152cod23003650\n---------------------------------------------\n  3     0.4512  0.0000  0.3333     E=(GE(1.0000))\n  6     0.3974  0.3022  0.2429     E=(O(1.0000))\n\nLocal parameters and GOALs for phase ZnO186cod90041780\n******************************************************\nSpacegroupNo=186\nHermannMauguin=P6_3mc\nXrayDensity=5.669\nRphase=9.52%\nUNIT=NM\nA=0.325072+-0.000011\nC=0.520812+-0.000030\nk1=0\nB1=0.003509+-0.000094\nGEWICHT=0.2266+-0.0021\nGrainSize(1,1,1)=120.9+-3.2\nAtomic positions for phase ZnO186cod90041780\n---------------------------------------------\n  2     0.3333  0.6667  0.0000     E=(ZN(1.0000))\n  2     0.3333  0.6667  0.3821     E=(O(1.0000))\n\nLocal parameters and GOALs for phase Zn2GeO4148cod90146310\n******************************************************\nSpacegroupNo=148\nHermannMauguin=R-3\nXrayDensity=4.777\nRphase=20.28%\nUNIT=NM\nA=1.423755+-0.000083\nC=0.952849+-0.000079\nk1=0.0100000\nB1=0.00500000\nGEWICHT=0.07959+-0.00075\nGrainSize(1,1,1)=84.1811\nAtomic positions for phase Zn2GeO4148cod90146310\n---------------------------------------------\n 18     0.2150  0.1940  0.5830     E=(ZN(1.0000))\n 18     0.5483  0.8607  0.5837     E=(ZN(1.0000))\n 18     0.2150  0.1940  0.2500     E=(GE(1.0000))\n 18     0.8877  0.4633  0.4293     E=(O(1.0000))\n 18     0.2220  0.1310  0.4030     E=(O(1.0000))\n 18     0.2230  0.1140  0.7500     E=(O(1.0000))\n 18     0.9957  0.6613  0.5833     E=(O(1.0000))\n', pattern_name='GeO2-ZnO_700C_60min.xy', num_steps=20, rp=9.96, rpb=19.06, r=10.99, rwp=12.04, rexp=2.69, d=0.1, rho=1.99, phases_results={'GeO2_152_(cod_2300365)-0': PhaseResult(spacegroup_no=152, hermann_mauguin='P3_121', xray_density=4.276, rphase=10.88, unit='NM', gewicht=(0.2793, 0.0012), gewicht_name=None, a=(0.499111, 2.4e-05), b=None, c=(0.564768, 3.3e-05), alpha=None, beta=None, gamma=None, k1=0.01, B1=0.005), 'ZnO_186_(cod_9004178)-0': PhaseResult(spacegroup_no=186, hermann_mauguin='P6_3mc', xray_density=5.669, rphase=9.52, unit='NM', gewicht=(0.2266, 0.0021), gewicht_name=None, a=(0.325072, 1.1e-05), b=None, c=(0.520812, 3e-05), alpha=None, beta=None, gamma=None, k1=0, B1=(0.003509, 9.4e-05)), 'Zn2GeO4_148_(cod_9014631)-0': PhaseResult(spacegroup_no=148, hermann_mauguin='R-3', xray_density=4.777, rphase=20.28, unit='NM', gewicht=(0.07959, 0.00075), gewicht_name=None, a=(1.423755, 8.3e-05), b=None, c=(0.952849, 7.9e-05), alpha=None, beta=None, gamma=None, k1=0.01, B1=0.005)})), phases=((RefinementPhase(path=PosixPath('cifs/GeO2_152_(cod_2300365)-0.cif'), params={}), RefinementPhase(path=PosixPath('cifs/GeO2_154_(cod_9007477)-0.cif'), params={})), (RefinementPhase(path=PosixPath('cifs/ZnO_186_(cod_9004178)-0.cif'), params={}),), (RefinementPhase(path=PosixPath('cifs/Zn2GeO4_148_(cod_9014631)-0.cif'), params={}),)), foms=((0.0,), (0.035359886962825535, 0.03528024374187284), (0.13639804324187943,), (0.33427282595205166,)), lattice_strains=((0.0,), (0.00018588822358559277, 0.00048125125325843384), (0.0005712782487738224,), (-0.0033382277696805732,)), missing_peaks=[], extra_peaks=[])]

In this pattern, we only have one solution found with Rwp = 12.04 %.

for i in range(len(search_results)):
    print(f"Rwp of solution {i} = {search_results[i].refinement_result.lst_data.rwp} %")
Rwp of solution 0 = 12.04 %

Each SearchResult has a visualize method to visualize the refined pattern and missing/extra peaks in the solution.

search_results[0].visualize()

You can also view all the alternative phases in one solution from SearchResult.phases attribute.

print("Phases found in solution 0:")
for i, phases_ in enumerate(search_results[0].phases):
    print(f"    - Phase {i}: {[phase.path.name for phase in phases_]}")
Phases found in solution 0:
    - Phase 0: ['GeO2_152_(cod_2300365)-0.cif', 'GeO2_154_(cod_9007477)-0.cif']
    - Phase 1: ['ZnO_186_(cod_9004178)-0.cif']
    - Phase 2: ['Zn2GeO4_148_(cod_9014631)-0.cif']

From the result, you can see that for the phase GeO2, the algorithm identifies two similar phases with slightly different spacegroups (SG 152 & 154)

previous

Tutorial 1: Automated Refinement

next

dara

Contents
  • Step 1: Prepare reference phases
  • Step 2: Search for phases
  • Step 3: Result analysis

By Yuxing Fei, Matthew J. McDermott

© Copyright 2024, Ceder Group.